home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / gtlayout-Source.lha / LTP_CreateGadgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-21  |  4.1 KB  |  176 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1994 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. VOID __regargs
  10. LTP_CreateGadgets(LayoutHandle *Handle,struct IBox *Bounds,LONG Left,LONG Top,LONG PlusWidth,LONG PlusHeight)
  11. {
  12.     if(!Handle -> Failed)
  13.     {
  14.         BOOLEAN    Fits;
  15.         BOOLEAN    Cloned = FALSE;
  16.         WORD    Attempt = 3;
  17.  
  18.         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  19.         {
  20.             LTP_Rescale(Handle,FALSE,FALSE);
  21.  
  22.             Handle -> Rescaled = FALSE;
  23.         }
  24.  
  25.         do
  26.         {
  27.             LTP_LayoutGroup(Handle,Handle -> TopGroup);
  28.             LTP_PlaceGroups(Handle,Handle -> TopGroup,Left,Top);
  29.  
  30.             Fits = TRUE;
  31.  
  32.             if(Handle -> TopGroup -> Width + PlusWidth > Bounds -> Width)
  33.             {
  34.                 if(Handle -> TopGroup -> Width + PlusWidth > Handle -> Screen -> Width)
  35.                 {
  36.                     Fits = FALSE;
  37.  
  38.                     if(Handle -> TopGroup -> Height + PlusHeight > Bounds -> Height)
  39.                     {
  40.                         if(!LTP_Rescale(Handle,TRUE,TRUE))
  41.                             Handle -> Failed = TRUE;
  42.                     }
  43.                     else
  44.                     {
  45.                         if(!LTP_Rescale(Handle,TRUE,FALSE))
  46.                             Handle -> Failed = TRUE;
  47.                     }
  48.                 }
  49.             }
  50.             else
  51.             {
  52.                 if(Handle -> TopGroup -> Height + PlusHeight > Bounds -> Height)
  53.                 {
  54.                     if(Handle -> TopGroup -> Height + PlusHeight > Handle -> Screen -> Height)
  55.                     {
  56.                         Fits = FALSE;
  57.  
  58.                         if(!LTP_Rescale(Handle,FALSE,TRUE))
  59.                             Handle -> Failed = TRUE;
  60.                     }
  61.                 }
  62.             }
  63.  
  64. #ifdef DO_CLONING
  65.             if(Handle -> Failed && !Cloned && Handle -> CloningPermitted)
  66.             {
  67.                 if(LTP_PrepareCloning(Handle))
  68.                     Bounds = &Handle -> CloneExtra -> Bounds;
  69.  
  70.                 Cloned = TRUE;
  71.             }
  72. #endif
  73.  
  74.             if(Attempt > 0 && Fits && !Handle -> Rescaled && !Cloned && !Handle -> Failed && (Handle -> GrowView || (Handle -> ResizeView && Handle -> Window)))
  75.             {
  76.                 LONG        Width    = Handle -> TopGroup -> Width + PlusWidth,
  77.                         Height    = Handle -> TopGroup -> Height + PlusHeight;
  78.                 ObjectNode    *View;
  79.  
  80.                 Attempt--;
  81.  
  82.                 if(Handle -> GrowView)
  83.                     View = Handle -> GrowView;
  84.                 else
  85.                     View = Handle -> ResizeView;
  86.  
  87.                 if(Bounds -> Width != Width || Bounds -> Height != Height)
  88.                 {
  89.                     LONG     PlusChars,
  90.                          PlusLines;
  91.  
  92.                     if(View -> Special . List . MaxGrowX && Handle -> GrowView)
  93.                     {
  94.                         PlusChars = (Bounds -> Width - Width) / Handle -> GlyphWidth;
  95.  
  96.                         if(PlusChars > 0 && View -> Chars + PlusChars > View -> Special . List . MaxGrowX)
  97.                             PlusChars = View -> Special . List . MaxGrowX - View -> Chars;
  98.  
  99.                         if(PlusChars < 0)
  100.                             PlusChars = 0;
  101.                     }
  102.                     else
  103.                     {
  104.                         if(View -> Special . List . ResizeX && !Handle -> GrowView)
  105.                             PlusChars = (Bounds -> Width - Width) / Handle -> GlyphWidth;
  106.                         else
  107.                             PlusChars = 0;
  108.                     }
  109.  
  110.                     if(View -> Special . List . MaxGrowY && Handle -> GrowView)
  111.                     {
  112.                         PlusLines = (Bounds -> Height - Height) / Handle -> RPort . TxHeight;
  113.  
  114.                         if(PlusLines > 0 && View -> Lines + PlusLines > View -> Special . List . MaxGrowY)
  115.                             PlusLines = View -> Special . List . MaxGrowY - View -> Lines;
  116.  
  117.                         if(PlusLines < 0)
  118.                             PlusLines = 0;
  119.                     }
  120.                     else
  121.                     {
  122.                         if(View -> Special . List . ResizeY && !Handle -> GrowView)
  123.                             PlusLines = (Bounds -> Height - Height) / Handle -> RPort . TxHeight;
  124.                         else
  125.                             PlusLines = 0;
  126.                     }
  127.  
  128.                     if(PlusChars != 0 || PlusLines != 0)
  129.                     {
  130.                         View -> Chars += PlusChars;
  131.                         View -> Lines += PlusLines;
  132.  
  133.                         LTP_ResetGroups(Handle -> TopGroup);
  134.  
  135.                         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  136.                         {
  137.                             LTP_Rescale(Handle,FALSE,FALSE);
  138.  
  139.                             Handle -> Rescaled = FALSE;
  140.                         }
  141.  
  142.                         Fits = FALSE;
  143.                     }
  144.                 }
  145.  
  146.                 Handle -> GrowView = NULL;
  147.             }
  148.         }
  149.         while(!Fits && !Handle -> Failed);
  150.  
  151. #ifdef DO_CLONING
  152.         if(!Handle -> Failed && Cloned)
  153.             LTP_CloneScreen(Handle,Handle -> TopGroup -> Width + PlusWidth,Handle -> TopGroup -> Height + PlusHeight);
  154. #endif
  155.  
  156.         if(!Handle -> Failed)
  157.         {
  158.             if(Handle -> GadgetArray = LTP_Alloc(Handle,sizeof(struct Gadget *) * Handle -> Count))
  159.             {
  160. #ifdef DO_PICKSHORTCUTS
  161.                 LTP_SearchKeys(Handle,Handle -> TopGroup);
  162.                 LTP_SelectKeys(Handle,Handle -> TopGroup);
  163. #endif
  164.                 LTP_LayoutGadgets(Handle,Handle -> TopGroup);
  165.  
  166.                 if(Handle -> Failed)
  167.                 {
  168.                     FreeGadgets(Handle -> List);
  169.  
  170.                     Handle -> List = NULL;
  171.                 }
  172.             }
  173.         }
  174.     }
  175. }
  176.